package com.example.system.log;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.stereotype.Component;

import java.lang.reflect.Modifier;

/**
 * @author 贾明祯
 * @ClassName KthLogAspect
 * @Date 2021/4/1 16:47
 * @Introduce
 */
@Component
@Aspect
public class KthLogAspect {

    @Pointcut("@annotation(com.example.system.log.KthLog)")//声明切点，自定义注解泪
    private void pointcut() {}

    @Before("pointcut() && @annotation(logger)")//拿去自定义注解对象
    public void advice(JoinPoint joinPoint , KthLog logger) {
        System.out.println("--- Kth日志的内容为[" + logger.value() + "] ---");
        System.out.println("注解作用的方法名: " + joinPoint.getSignature().getName());

        System.out.println("所在类的简单类名: " + joinPoint.getSignature().getDeclaringType().getSimpleName());

        System.out.println("所在类的完整类名: " + joinPoint.getSignature().getDeclaringType());

        System.out.println("目标方法的声明类型: " + Modifier.toString(joinPoint.getSignature().getModifiers()));

    }

//    @Around("pointcut() && @annotation(logger)")
//    public Object advice(ProceedingJoinPoint joinPoint, KthLog logger) {
//        System.out.println("["
//                + joinPoint.getSignature().getDeclaringType().getSimpleName()
//                + "][" + joinPoint.getSignature().getName()
//                + "]-日志内容-[" + logger.value() + "]");
//
//        Object result = null;
//
//        try {
//            result = joinPoint.proceed();
//        } catch (Throwable throwable) {
//            throwable.printStackTrace();
//        }
//
//        return result;
//    }


}
